In an appropriate directory, run the following commands to clone the example git repository.
$ git clone https://github.com/csc-training/python-quality-exercise.git
$ cd python-quality-exercise
Now you are in the repository. You can view the README file for an explanation.
Create a virtual environment (with Python3 with the following
$ virtualenv -p python3 python-quality
[...]
$ source python-quality/bin/activate
(python-quality) $
Install the required package versions with
(python-quality) $ pip install -r requirements.txt
Now, whenever you want to activate the virtual environment you run:
$ source python-quality/bin/activate
(python-quality) $
```
You can now run tests using pytest with
(python-quality) $ pytest
Go ahead and find out the functions you can test and write unit tests for some of them.
You might want to use mock for some tests, for instance to avoid the initialization of DemoClass, but at least the find_median function should be simple to test with a few examples.
To make the package installable, you should put a setup.py at the top level.
A minimal one like in the Python documentation will suffice. The name of the package you wish to expose is, of course demolib.
Go ahead and make a setup script. You can test that the package is installable with
(python-quality) $ pip install .
To facilitate running test for more than one version of python, use tox.
Create a file called tox.ini, with the following contents
[tox]
envlist = py27,py35
[testenv]
deps= -rrequirements.txt
commands=py.test --cov demolib # run pytest
pep8 # run pep8
If you still have any errors go ahead and fix them.
You should now be able to run tox with
(python-quality) $ tox
That's it. If you had an open source project you could e.g. enable Travis to automatically run your tests and style checks against every branch your team makes.